package cn.hftoday.org;

import cn.hftoday.db.*;
import junit.framework.TestCase;
import cn.hftoday.util.*;
import cn.hftoday.core.*;

public class OrganizationTypeTest extends TestCase {

	protected void setUp() throws Exception {
		ApplicationConfig.getInstance().load();
		ConnectionPool.getInstance().open();
		ConnectionPool.getInstance().beginTransaction();
	}

	protected void tearDown() throws Exception {
		ConnectionPool.getInstance().rollback();
		ConnectionPool.getInstance().close();
	}

	public void testGetId() {
		OrganizationType ot = new OrganizationType();
		ot.setId("abc...def");
		assertEquals(ot.getId(), "abc...def");
	}

	public void testGetName() {
		OrganizationType ot = new OrganizationType();
		ot.setName("abc...def");
		assertEquals(ot.getName(), "abc...def");
	}
	
	public void testGetIcon() {
		OrganizationType ot = new OrganizationType();
		ot.setIcon("abc...def");
		assertEquals(ot.getIcon(), "abc...def");
	}
	
	public void testSelect() {
		testInsert();
		OrganizationType ot = (OrganizationType)Mapper.getInstance().queryForObject("SelectOrganizationTypeById", "abc...def");
		assertEquals(ot.getId(), "abc...def");
		assertEquals(ot.getName(), "123456");
		assertEquals(ot.getIcon(), "wer/jkk.jpg.png");
	}

	public void testInsert() {
		OrganizationType ot = new OrganizationType();
		ot.setId("abc...def");
		ot.setName("123456");
		ot.setIcon("wer/jkk.jpg.png");
		Object o = Mapper.getInstance().insert("InsertOrganizationType", ot);
		assertEquals(ot, o);
	}
	
	public void testUpdate() {
		testInsert();
		OrganizationType ot = (OrganizationType)Mapper.getInstance().queryForObject("SelectOrganizationTypeById", "abc...def");
		ot.setName("123456789");
		ot.setIcon("wer/jkk.jpg");
		Mapper.getInstance().update("UpdateOrganizationType", ot);
		ot = (OrganizationType)Mapper.getInstance().queryForObject("SelectOrganizationTypeById", "abc...def");
		assertEquals(ot.getName(), "123456789");
		assertEquals(ot.getIcon(), "wer/jkk.jpg");
	}
	
	public void testDelete() {
		testInsert();
		OrganizationType ot = (OrganizationType)Mapper.getInstance().queryForObject("SelectOrganizationTypeById", "abc...def");
		Mapper.getInstance().delete("DeleteOrganizationType", ot);
		ot = (OrganizationType)Mapper.getInstance().queryForObject("SelectOrganizationTypeById", "abc...def");
		assertEquals(ot, null);
	}
}
